package edu.kaist.cs408.pof.android;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;

import java.util.ArrayList;


/*
		 * public SimpleExpandableListAdapter (
		 * 	Context context,
		 * List<? extends Map<String, ?>> groupData,
		 * int groupLayout,
		 * String[] groupFrom,
		 * int[] groupTo,
		 * List<? extends List<? extends Map<String, ?>>> childData,
		 * int childLayout,
		 * String[] childFrom,
		 * int[] childTo)

			Since: API Level 1
			Constructor
			Parameters
			context	The context where the ExpandableListView associated with this SimpleExpandableListAdapter is running
			groupData	A List of Maps. Each entry in the List corresponds to one group in the list. The Maps contain the data for each group, and should include all the entries specified in "groupFrom"
			groupLayout	resource identifier of a view layout that defines the views for a group. The layout file should include at least those named views defined in "groupTo"
			groupFrom	A list of keys that will be fetched from the Map associated with each group.
			groupTo	The group views that should display column in the "groupFrom" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the groupFrom parameter.
			childData	A List of List of Maps. Each entry in the outer List corresponds to a group (index by group position), each entry in the inner List corresponds to a child within the group (index by child position), and the Map corresponds to the data for a child (index by values in the childFrom array). The Map contains the data for each child, and should include all the entries specified in "childFrom"
			childLayout	resource identifier of a view layout that defines the views for a child. The layout file should include at least those named views defined in "childTo"
			childFrom	A list of keys that will be fetched from the Map associated with each child.
			childTo	The child views that should display column in the "childFrom" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the childFrom parameter.
		 */

public class MyListAdapter extends BaseAdapter {
	Context maincon;
	LayoutInflater Inflater;
	ArrayList<MyItem> arSrc;
	int layout;

	public MyListAdapter(Context context, int alayout, ArrayList<MyItem> aarSrc) {
		maincon = context;
		Inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		arSrc = aarSrc;
		layout = alayout;
	}

	public int getCount() {
		return arSrc.size();
	}

	public String getItem(int position) {
		return arSrc.get(position).Name;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		final int pos = position;
		if (convertView == null)
			convertView = Inflater.inflate(layout, parent, false);
		ImageView img = (ImageView) convertView.findViewById(R.id.cartImg);
		img.setImageResource(arSrc.get(position).Icon);

		TextView txt = (TextView) convertView.findViewById(R.id.cartText);
		txt.setText(arSrc.get(position).Name);

		Button callbtn = (Button) convertView.findViewById(R.id.callBtn);
		Button delbtn = (Button) convertView.findViewById(R.id.delBtn);

		delbtn.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				Toast.makeText(maincon, "�ٺ�", Toast.LENGTH_SHORT).show();
			}
		});

		callbtn.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {

				Toast.makeText(maincon, "õ��", Toast.LENGTH_SHORT).show();
			}
		});

		return convertView;
	}

}
